package com.LeetCode.doublePair;

import org.junit.Test;

/**
 * 剩水最多的容器
 */
public class MostWater {
    public int maxArea(int[] height){
        int maxArea = 0 , l = 0, r = height.length - 1;
        while(l<r){
            maxArea = Math.max(Math.min(height[l] , height[r]) * (r - l) , maxArea);

            if(height[l] < height[r]){
                l++;
            }else{
                r--;
            }
        }
        return maxArea;
    }

    public int maxWater(int[] height){
        int len = height.length;
        int res = 0;
        int l = 0, r = len - 1;
        while(l < r){
            res = height[l] < height[r] ?
                    Math.max(res,  (r - l) * height[l++]) :
                    Math.max(res,  (r - l) * height[r--]);
        }
        return res;
    }

    @Test
    public void test(){
        int[] arr = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxWater(arr));

    }
}
